const initState = {
	username: '张三',
	list: [1, 2, 3, 4, 5]
}

export interface State {
	username: string
	list: number[]
}

export const ADD_LIST = 'ADD_LIST'
export const DELETE_LIST = 'DELETE_LIST'
export const QWEQWE = 'QWEQWE'


export function addList(payload: number) {
	return { type: ADD_LIST, payload }
}


export function deleteList(payload: number) {
	return { type: DELETE_LIST, payload }
}

export function qweqweqe(payload: boolean) {
	return { type: QWEQWE, payload }
}

interface AddListAction {
	type: typeof ADD_LIST
	payload: number
}

interface DELETEListAction {
	type: typeof DELETE_LIST
	payload: number
}

interface QWEQWEAction {
	type: typeof QWEQWE
	payload: boolean
}


type ActionType = AddListAction | DELETEListAction | QWEQWEAction


const reducer = (state: State = initState, action: ActionType) => {
	switch (action.type) {
		case ADD_LIST: 
			return {
				...state,
				list: [...state.list, action.payload]
			}
		case DELETE_LIST:
			return {
				...state,
				list: state.list.filter((v, i) => i !== action.payload)
			}
		default:
			return state
	}
}


export default reducer